// pages/children/children.js
const app=getApp()
var startX, endX;
var moveFlag = true;// 判断执行滑动事件

Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    content:"adan_1.png",
    _id:1
  },
  touchStart: function (e) {
    startX = e.touches[0].pageX; // 获取触摸时的原点
    moveFlag = true;
  },
  // 触摸移动事件
  touchMove: function (e) {
    endX = e.touches[0].pageX; // 获取触摸时的原点

    if (moveFlag) {
      if (endX - startX > 50) {
        // console.log("move right");
        this.move2right();
        moveFlag = false;
      }
      if (startX - endX > 50) {
        // console.log("move left");
        this.move2left();
        moveFlag = false;
      }
    }

  },
  // 触摸结束事件
  touchEnd: function (e) {
    moveFlag = true; // 回复滑动事件
    
  },

  move2left() {
    var that = this;
    console.log(this.data.content)
    // console.log('向右滑动')
    if(this.data.content=='adan_1.png'){

      that.setData({
        content: "adan_2.png",
        _id:2
      });
    }
    else if(this.data.content=='adan_2.png'){

      that.setData({
        content: "adan_3.png",
        _id:3
      });
    }
    else if(this.data.content=='adan_3.png'){
  
      that.setData({
        content: "adan_4.png",
        _id:4
      });
    }
    else if(this.data.content=='adan_4.png'){
  
      that.setData({
        content: "adan_5.png",
        _id:5
      });
    }
    else if(this.data.content=='adan_5.png'){
  
      that.setData({
        content: "adan_6.png",
        _id:6
      });
    }
    else if(this.data.content=='adan_6.png'){
  
      that.setData({
        content: "adan_7.png",
        _id:7

      });
    }
    else if(this.data.content=='adan_5.png'){
  
      that.setData({
        content: "adan_6.png",
        _id:8
      });
    }
    else if(this.data.content=='adan_7.png'){
  
      that.setData({
        content: "adan_8.png",
        _id:9
      });
    }
    else if(this.data.content=='adan_8.png'){
  
      that.setData({
        content: "adan_9.png",
        _id:10
      });
    }
    else if(this.data.content=='adan_9.png'){
  
      that.setData({
        content: "adan_10.png",
        _id:11
      });
    }
    else if(this.data.content=='adan_10.png'){
  
      that.setData({
        content: "adan_11.png",
        _id:12
      });
    }
    else if(this.data.content=='adan_11.png'){
  
      that.setData({
        content: "adan_12.png",
        _id:12
      });
    }
    else if(this.data.content=='adan_12.png'){
  
      that.setData({
        content: "adan_1.png",
        _id:1
      });
    }
   
  },
  move2right() {
    var that = this;
    console.log(this.data.content)

    if(this.data.content=='adan_1.png'){

      that.setData({
        content: "adan_12.png",
        _id:12
      });
    }
    else if(this.data.content=='adan_2.png'){

      that.setData({
        content: "adan_1.png",
        _id:1
      });
    }
    else if(this.data.content=='adan_3.png'){
  
      that.setData({
        content: "adan_2.png",
        _id:2
      });
    }
    else if(this.data.content=='adan_4.png'){
  
      that.setData({
        content: "adan_3.png",
        _id:3
      });
    }
    else if(this.data.content=='adan_5.png'){
  
      that.setData({
        content: "adan_4.png",
        _id:4
      });
    }
    else if(this.data.content=='adan_6.png'){
  
      that.setData({
        content: "adan_5.png",
        _id:5
      });
    }
    else if(this.data.content=='adan_7.png'){
  
      that.setData({
        content: "adan_6.png",
        _id:6
      });
    }
    else if(this.data.content=='adan_8.png'){
  
      that.setData({
        content: "adan_7.png",
        _id:7
      });
    }
    else if(this.data.content=='adan_9.png'){
  
      that.setData({
        content: "adan_8.png",
        _id:8
      });
    }
    else if(this.data.content=='adan_10.png'){
  
      that.setData({
        content: "adan_9.png",
        _id:9
      });
    }
    else if(this.data.content=='adan_11.png'){
  
      that.setData({
        content: "adan_10.png",
        _id:10
      });
    }
    else if(this.data.content=='adan_12.png'){
  
      that.setData({
        content: "adan_11.png",
        _id:11
      });
    }

  },
  click:function(){
    // console.log(2)
    console.log(this.data.content)
  }
})